package com.example.actordemo3.config;

import akka.actor.Actor;
import akka.actor.IndirectActorProducer;
import org.springframework.context.ApplicationContext;

public class SpringActorProduct implements IndirectActorProducer {

    private  final ApplicationContext applicationContext;
    private  final  String actorName;

    private final  Object[] ags;

    public SpringActorProduct(ApplicationContext applicationContext, String actorName, Object[] ags) {
        this.applicationContext = applicationContext;
        this.actorName = actorName;
        this.ags = ags;
    }

    @Override
    public Actor produce() {
        return (Actor)applicationContext.getBean(actorName,ags);
    }

    @Override
    public Class<? extends Actor> actorClass() {
        return (Class<? extends Actor>) applicationContext.getType(actorName);
    }
}
